#include "resultdetailwidget.h"

// Qt Includes
#include <QFileInfo>

/////////////////////////////////////////////////////////////////////
// Construction & Destruction
/////////////////////////////////////////////////////////////////////
CResultDetailWidget::CResultDetailWidget(QWidget *pParent/* = NULL*/, Qt::WFlags windowFlags/* = 0*/)
	: QWidget(pParent, windowFlags)
{
	setupUi(this);

	// Until we have the detail, we hide all fields.
	m_pFileNameLabel->setVisible(false);
	m_pPluginNameLabel->setVisible(false);
	m_pSeverityLabel->setVisible(false);
	m_pCodeLabel->setVisible(false);
	m_pSourceCodeLabel->setVisible(false);
}
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
// Member Functions
/////////////////////////////////////////////////////////////////////
void CResultDetailWidget::setFileName(const QString &strFileName)
{
	if(strFileName.isEmpty())
	{
		// Hide the filename widget.
		m_pFileNameLabel->setText(QString());
		m_pFileNameLabel->setVisible(false);
		return;
	}

	const QFileInfo theFileInfo(strFileName);
	QString strText("<img src=\"%1\" width=\"16\" height=\"16\" />&nbsp;%2");

	if(theFileInfo.suffix().toLower() == "h")
	{
		strText = strText.arg(":/Icons/File_H");
	}
	else if(theFileInfo.suffix().toLower() == "cpp")
	{
		strText = strText.arg(":/Icons/File_CPP");
	}

	m_pFileNameLabel->setText(strText.arg(strFileName));

	// Show the filename widget.
	m_pFileNameLabel->setVisible(true);
}

void CResultDetailWidget::setPluginDetails(const QString &strPluginName, const QString &strDescription)
{
	if(strPluginName.isEmpty())
	{
		// Hide the plugin widget.
		m_pPluginNameLabel->setText(QString());
		m_pPluginNameLabel->setVisible(false);
		return;
	}

	m_pPluginNameLabel->setText(QString("<img src=\":/Icons/FileScanner\" width=\"16\" height=\"16\" />&nbsp;%1")
			.arg(strPluginName));
	m_pPluginNameLabel->setToolTip(strDescription);

	// Show the plugin widget.
	m_pPluginNameLabel->setVisible(true);
}

void CResultDetailWidget::setSeverity(quint8 nSeverity)
{
	if(nSeverity == 0)
	{
		// Hide the severity widget.
		m_pSeverityLabel->setText(QString());
		m_pSeverityLabel->setVisible(false);
		return;
	}
	m_pSeverityLabel->setText(QString("<img src=\":/Icons/Severity\" width=\"16\" height=\"16\" />&nbsp;%1")
			.arg(nSeverity));

	// Show the severity widget.
	m_pSeverityLabel->setVisible(true);
}

void CResultDetailWidget::setCode(const QString &strCode)
{
	if(strCode.isEmpty())
	{
		// Hide the code widgets.
		m_pSourceCodeLabel->setText(QString());
		m_pCodeLabel->setVisible(false);
		m_pSourceCodeLabel->setVisible(false);
		return;
	}

	m_pSourceCodeLabel->setText(strCode);

	// Show the code widgets.
	m_pCodeLabel->setVisible(true);
	m_pSourceCodeLabel->setVisible(true);
}
/////////////////////////////////////////////////////////////////////
